﻿using AutoMapper;
using Modules.BankSpecialAccount.Entitys;
using Modules.Project;
using PmSoft;
using static Modules.BankSpecialAccount.BankSpecialAccountConstants;

namespace ManagementApi.Models.Manage.ProjectSpecialAccount
{
    public class ProjectSpecialAccountPaymentDetailsDto
    {
        public int Id { get; set; }

        /// <summary>
        /// 项目ID
        ///</summary>
        public int ProjectId { get; set; }

        /// <summary>
        /// 流水号（HTSerial）
        ///</summary>
        public int HTSerial { get; set; }

        /// <summary>
        /// 代发批次号（批次号PCSerial）
        ///</summary>
        public int BatchNo { get; set; }

        /// <summary>
        /// 发放总数（FFTotalNum）
        ///</summary>
        public int NumberIssued { get; set; }

        /// <summary>
        /// 发放总额（FFTotalAmount）
        ///</summary>
        public int AmountIssued { get; set; }

        /// <summary>
        /// 交易流水号（JYBrook）
        ///</summary>
        public int TradeSerial { get; set; }

        /// <summary>
        /// 交易日期（JYDate）
        ///</summary>
        public int TradeDate { get; set; }

        /// <summary>
        /// 交易时间（JYTime）
        ///</summary>
        public int TradeTime { get; set; }

        /// <summary>
        /// 发卡账号（FKAccount）
        ///</summary>
        public int BankAccount { get; set; }

        /// <summary>
        /// 发卡户名（FKAccountName）
        ///</summary>
        public int BankAccountName { get; set; }

        /// <summary>
        /// 交易币种（JYBZ）
        ///</summary>
        public int Currency { get; set; }

        /// <summary>
        /// 交易金额（JYAmount）
        ///</summary>
        public int TradeAmount { get; set; }

        /// <summary>
        /// （收）账号（SKAccount）
        ///</summary>
        public int PayeeAccount { get; set; }

        /// <summary>
        /// （收）户名（SKAccountName）
        ///</summary>
        public int PayeeAccountName { get; set; }

        /// <summary>
        /// （收）证件类别（SKZJLB）
        ///</summary>
        public int PayeeCertType { get; set; }

        /// <summary>
        /// （收）证件号码（SKZJHM）
        ///</summary>
        public int PayeeCertNo { get; set; }

        /// <summary>
        /// 交易摘要
        ///</summary>
        public int TradeAbstract { get; set; }

        /// <summary>
        /// 交易结果
        ///</summary>
        public int TradeResult { get; set; }

        /// <summary>
        /// KHTag
        ///</summary>
        public int KHTag { get; set; }

        /*扩展字段*/

        /// <summary>
        /// 项目名称
        /// </summary>
        public string PrjName { get; set; }

        /// <summary>
        /// 项目编号
        /// </summary>
        public string PrjNum { get; set; }
    }

    public static partial class ProjectSpecialAccountPaymentDetailsExceptions
    {
        /// <summary>
        /// 补充信息
        /// </summary>
        /// <param name="specialAccountPaymentDetails"></param>
        /// <returns></returns>
        public static ProjectSpecialAccountPaymentDetailsDto AsProjectSpecialAccountPaymentDetailsDto(this BankSpecialAccountPaymentDetails specialAccountPaymentDetails)
        {
            ProjectSpecialAccountPaymentDetailsDto dto = new ProjectSpecialAccountPaymentDetailsDto();
            var mapper = ServiceAccessor.GetService<IMapper>();
            mapper.Map(specialAccountPaymentDetails, dto);
            var projectService = ServiceAccessor.GetService<ProjectService>();
            ProjectInfo projectInfo = projectService.GetProjectInfo(specialAccountPaymentDetails.ProjectId) ?? new ProjectInfo();
            dto.PrjName = projectInfo.Name;
            dto.PrjNum = projectInfo.PrjNum;
            return dto;
        }
    }
}